package com.ygy.jxc;


import com.ygy.jxc.constant.SystemConstant;
import com.ygy.jxc.controller.XtAdminController;
import com.ygy.jxc.dto.AdminLoginParam;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.sql.DataSource;
import java.math.BigDecimal;
import java.util.*;

/**
 *   1. 数据库链接测试
 *   2. 密码加密
 */

//@RunWith(SpringRunner.class)    测试报not exit 但能正常运行
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class test {
    @Autowired
    private XtAdminController xtAdminController;

    @Autowired
    DataSource dataSource;

    /**
     * 测试数据库是否连接成功
     *
     * @throws Exception
     */
    @Test
    public void contextLoads() throws Exception {
        System.out.println("获取的数据库连接为:" + dataSource.getConnection());
    }


    @Test
    public void loginTest() throws Exception {

        String TempPwd="123456";
        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        String  pwd = bCryptPasswordEncoder.encode(TempPwd);
        System.out.println(TempPwd+":加密后的密码:\t"+pwd);
    }

    /**    util--------->  calculationUtils
     * 计算公式 容积换算为kg
     *                  (kg)公斤 = (volume)容积（长cmx宽cmx高cm）/6000
     *
     *                  Volume  容积立方米
     */
    @Test
    public void INTCalculatingVolumeToWeight() {
        Long Volume = 6l;  //传递的仓库容量立方米
        Volume = Volume * SystemConstant.SQUARECEMETERTONTIMETER;     //转为立方厘米
//        System.out.println(Volume);
        BigDecimal a = new BigDecimal(String.valueOf(Volume));
        BigDecimal weight = a.divide(BigDecimal.valueOf(SystemConstant.DENOMINATOR), 0);

      System.out.println(weight);
    }

}
